package com.goods.business.converter;

import com.goods.business.service.ConsumerService;
import com.goods.common.model.business.Consumer;
import com.goods.common.response.ResponseBean;
import com.goods.common.utils.ListPageUtils;
import com.goods.common.vo.system.PageVO;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(value = "物资去处")
@RestController
@RequestMapping("/business/consumer")
public class ConsumerController {
    //business/consumer/findConsumerList?pageNum=1&pageSize=10&name=daf&address=dsfas&contact=sfad
    //Request Method: GET

    @Autowired
    private ConsumerService consumerService;

    @GetMapping("/findConsumerList")
    public ResponseBean findConsumerList(Integer pageNum,Integer pageSize,String name,String contact,String address){
        List<Consumer> consumerList =  consumerService.findConsumerList(name,contact,address);
        List<Consumer> page = ListPageUtils.page(consumerList, pageSize, pageNum);
        PageVO<Consumer> consumerPageVO = new PageVO<>(consumerList.size(), page);
        return ResponseBean.success(consumerPageVO);
    }
/*
    consumer/add
    Request Method: POST*/
    @PostMapping("add")
    public ResponseBean add(@RequestBody Consumer consumer){
        consumerService.add(consumer);
        return ResponseBean.success();
    }


/*/business/consumer/edit/28
    Request Method: GET*/
    @GetMapping("edit/{id}")
    public ResponseBean edit(@PathVariable Long id){
        Consumer consumer = consumerService.edit(id);
        return ResponseBean.success(consumer);
    }
//     http://www.localhost:8989/business/consumer/update/28
//Request Method: PUT
    @PutMapping("/update/{id}")
    public ResponseBean update(@PathVariable Long id,@RequestBody Consumer consumer){
        consumerService.update(consumer);
        return ResponseBean.success();
    }

    @DeleteMapping("/delete/{id}")
    public ResponseBean delete(@PathVariable Long id){
        consumerService.delete(id);
        return ResponseBean.success();
    }


    //http://www.localhost:8989/business/consumer/findAll
    //Request Method: GET
    @GetMapping("findAll")
    public ResponseBean findAll(){
        List<Consumer> consumerList=  consumerService.findAll();
        return ResponseBean.success(consumerList);
    }



}
